//
//  commentview.m
//  testvideo
//
//  Created by fcbayern on 2021/1/3.
//  Copyright © 2021 fcbayern. All rights reserved.
//

#import "commentview.h"
#import "Masonry.h"
#import "commentcell.h"
#import "Single.h"

@interface commentview ()
@property(strong,nonatomic)UITableView * tableview;
@property(strong,nonatomic)NSMutableArray * myarray;
@property(strong,nonatomic)UILabel * test;

@end

@implementation commentview

- (void)viewWillAppear:(BOOL)animated{
    [super viewDidLoad];
    CAGradientLayer *gradientLayer = [[CAGradientLayer alloc] init];
    gradientLayer.colors = @[(__bridge id)[UIColor whiteColor].CGColor,(__bridge id)[UIColor blackColor].CGColor];
        gradientLayer.startPoint = CGPointMake(0, 0);
        gradientLayer.endPoint = CGPointMake(1, 1);
        gradientLayer.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame));
    [self.view.layer addSublayer:gradientLayer];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStyleDone target:self action:@selector(dismiss)];
    self.title = @"查看评论";
    _myarray = [Single sharedInstance].singlecomment;
     [_tableview reloadData];
    _test = [[UILabel alloc] init];
    [self.view addSubview:_test];
    [_test mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(30);
        make.width.equalTo(self.view);
        make.height.equalTo(self.view).multipliedBy(0.1);
    }];
    
    _tableview = [[UITableView alloc] init];
    self.tableview.backgroundColor = UIColor.clearColor;
    [self.view addSubview:_tableview];
    [_tableview mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.equalTo(self.view).multipliedBy(0.9);
        make.height.equalTo(self.view);
        make.centerX.equalTo(self.view);
        make.centerY.equalTo(self.view);
    }];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    return 150;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 20;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [UIView new];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return [UIView new];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _myarray.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    commentcell * cell = [tableView dequeueReusableCellWithIdentifier:@"commentcell"];
    if (cell == nil) {
        cell = [[commentcell alloc] init];
    }
    NSString * usernametext = [[NSString alloc] initWithFormat:@"%@ %@",_myarray[indexPath.section][@"PublisherName"],@": "];
    cell.username.text = usernametext;
    cell.commentdetail.text = _myarray[indexPath.section][@"Content"];
    cell.layer.cornerRadius = 20;
    cell.layer.borderWidth = 2;
    CGColorSpaceRef colorSpaceRef = CGColorSpaceCreateDeviceRGB();
    CGColorRef color = CGColorCreate(colorSpaceRef, (CGFloat[]){0.1,0,0,0.1});
    cell.layer.borderColor = color;
    return cell;
}

- ( void )tableView:( UITableView *)tableView willDisplayCell :( UITableViewCell *)cell forRowAtIndexPath :( NSIndexPath *)indexPath{
    cell.backgroundColor = [ UIColor whiteColor ];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
